﻿using System;
namespace UniMana.Win.Training
{
    public partial class xucDay : DevExpress.XtraEditors.XtraUserControl
    {
        private int m_iDayOfWeek;
        private xucSession session1;
        private xucSession session2;
        private xucSession session3;
        private xucSession[] m_arSession;

        private DateTime m_dStartTime, m_dEndTime;

        public delegate void onAddClass(xucClass obj);
        public event onAddClass OnAddClass;
        public delegate void onSave(xucDay _xucDay, xucSession _xucSesion, xucClass _xucClass);
        public event onSave OnSave;
        public delegate void onChangeDay(xucDay _xucDay, xucSession _xucSesion, xucClass _xucClass);
        public event onChangeDay OnChangeDay;
        public delegate void onChooseChange(xucDay _xucDay, xucSession _xucSesion, xucClass _xucClass);
        public event onChooseChange OnChooseChange;

        public xucDay(xucDay.DayOfWeek _dOW, DateTime _dStartTime, DateTime _dEndTime)
        {            
            InitializeComponent();
            
            this.m_iDayOfWeek = (int)_dOW;

            this.session1 = new xucSession(xucSession.Session.Session1, m_iDayOfWeek, m_dStartTime, m_dEndTime);
            this.session2 = new xucSession(xucSession.Session.Session2, m_iDayOfWeek, m_dStartTime, m_dEndTime);
            this.session3 = new xucSession(xucSession.Session.Session3, m_iDayOfWeek, m_dStartTime, m_dEndTime);
            
            this.m_arSession = new xucSession[] { session1, session2, session3 };

            this.xtraScrollableControl1.Controls.Add(this.session1);
            this.xtraScrollableControl1.Controls.Add(this.session2);
            this.xtraScrollableControl1.Controls.Add(this.session3);

            this.session1.Show();
            this.session2.Show();
            this.session3.Show();

            this.Left = (this.m_iDayOfWeek - 1) * (this.Width + 10);

            this.session1.OnAddClass += new xucSession.onAddClass(Event_AddClass);
            this.session2.OnAddClass += new xucSession.onAddClass(Event_AddClass);
            this.session3.OnAddClass += new xucSession.onAddClass(Event_AddClass);

            this.session1.OnSave += new xucSession.onSave(Event_SaveXucClass);
            this.session2.OnSave += new xucSession.onSave(Event_SaveXucClass);
            this.session3.OnSave += new xucSession.onSave(Event_SaveXucClass);

            this.session1.OnChangeDay += new xucSession.onChangeDay(Event_OnChangeDay);
            this.session2.OnChangeDay += new xucSession.onChangeDay(Event_OnChangeDay);
            this.session3.OnChangeDay += new xucSession.onChangeDay(Event_OnChangeDay);

            this.session1.OnChooseChange += new xucSession.onChooseChange(Event_OnChooseChange);
            this.session2.OnChooseChange += new xucSession.onChooseChange(Event_OnChooseChange);
            this.session3.OnChooseChange += new xucSession.onChooseChange(Event_OnChooseChange);

           
        }

        public enum DayOfWeek
        {
            Mo = 1,
            Tu = 2,
            We = 3,
            Th = 4,
            Fr = 5,
            Sa = 6,
            Su = 7,
            Un = 8
        }

        public xucSession Session1
        {
            get { return this.session1; }
        }

        public xucSession Session2
        {
            get { return this.session2; }
        }

        public xucSession Session3
        {
            get { return this.session3; }
        }

        public xucSession[] ListSession
        {
            get { return this.m_arSession; }
        }

        private void Event_AddClass(xucClass obj)
        {
            if (OnAddClass != null) OnAddClass(obj);
        }

        private void Event_SaveXucClass(xucSession objSession, xucClass objClass)
        {
            if (OnSave != null) OnSave(this, objSession, objClass);
        }

        private void Event_OnChangeDay(xucSession objSession, xucClass objClass)
        {
            if (OnChangeDay != null) OnChangeDay(this, objSession, objClass);
        }

        private void Event_OnChooseChange(xucSession objSession, xucClass objClass)
        {
            if (OnChooseChange != null) OnChooseChange(this,objSession,objClass);
        }

        public void AddClass(int _iSession, int _iTraining_SubjectOpenRequestKey)
        {
            if (_iSession == 1)
            {
                this.session1.AddClass(_iTraining_SubjectOpenRequestKey);
            }
            if (_iSession == 2)
            {
                this.session2.AddClass(_iTraining_SubjectOpenRequestKey);
            }
            if (_iSession == 3)
            {
                this.session3.AddClass(_iTraining_SubjectOpenRequestKey);
            }
            
        }

        public void AddClass(xucClass _xucClass)
        {
            for (int i = 0; i < this.m_arSession.Length; i++)
            {
                if (this.m_arSession[i].iSession == _xucClass.Session)
                {
                    this.m_arSession[i].AddClass(_xucClass.Training_SubjectOpenRequestKey);
                    break;
                }
            }
        }

        public DateTime DteStart
        {
            get { return Cache.m_dteLuuTam1; }
        }

        public DateTime DteEnd
        {
            get { return Cache.m_dteLuuTam2; }
        }
        
        public int iDayOfWeek
        {
            get { return this.m_iDayOfWeek; }
        }

        private void xucDay_Load(object sender, EventArgs e)
        {
            this.Height = this.Parent.Height;
        }

        private void xtraScrollableControl1_Click(object sender, EventArgs e)
        {
            
        }
    }
}
